<?php
$this->load->view('header');

if (strlen($this->session->userdata('Error')) > 0) {
    echo '<div class="alert alert-danger alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->userdata('Error') . '</div>';
    $this->session->unset_userdata('Error');
} elseif (strlen($this->session->userdata('Success')) > 0) {
    echo '<div class="alert alert-success alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->userdata('Success') . '</div>';
    $this->session->unset_userdata('Success');
}
?>

<script type="text/javascript">

    function search_data() {
        $.post("<?= site_url() ?>setup/search_area", {
            search_by_regional: $('#search_by_regional').val(),
            search_by_status: $('#search_by_status').val(),
            search_by_type: $('#search_by_type').val()
        },
        function(data) {
            $('#tablecontent').html(data);
        });
    }

    function edit_data(id) {
        $.post("<?= site_url() ?>/setup/edit_area", {id: id}, function(data) {
            $('#loader').html(data);
        });
    }

    function close_popup() {
        $('#dialog').dialog('close');
    }

    function load_page_area(page, ipp) {
        $.post("<?= site_url() ?>setup/load_page_area", {
            page: page,
            ipp: ipp,
            search_by_regional: $('#search_by_regional').val(),
            search_by_status: $('#search_by_status').val(),
            search_by_type: $('#search_by_type').val()
        },
        function(data) {
            $('#tablecontent').html(data);
        });
    }


    function add_data() {
        $.post("<?= site_url() ?>setup/add_area", function(data) {
            $('#loader').html(data);
        });
    }
</script>

<div id="loader">
    <div class="row" style="margin-top:40px">
        <form method=post id="access" action="#" enctype="multipart/form-data" class="form-horizontal" role="form">
            <div class="container well">
                <h4><b class="caret"></b><b> Search Area</b></h4>
                <div class="col-sm-5">
                    <div class="col-sm-4"><label for="officename" class="control-label">Office Name</label></div>
                    <div class="col-sm-8"><input type="text" class="form-control input-sm" id="search_by_regional" name="search_by_regional"></div>
                </div>
                <div class="col-sm-5">
                    <div class="col-sm-4"><label for="status" class="control-label">Status</label></div>
                    <div class="col-sm-8">
                        <select name="search_by_status" id="search_by_status" class="form-control">
                            <option value="">-- select --</option>
                            <option value="Y">Active</option>
                            <option value="N">Non Active</option>
                        </select>
                    </div>
                </div>		
                <div class="col-sm-5">
                    <div class="col-sm-4"><label for="type" class="control-label">Type</label></div>
                    <div class="col-sm-8">
                        <select name="search_by_type" id="search_by_type" class="form-control">
                            <option value="">-- select --</option>
                            <option value="Y">Domestik</option>
                            <option value="N">Internasional</option>
                        </select>
                    </div>
                </div>
                <div class="col-sm-8">
                    <div class="col-sm-4">

                    </div>
                </div>
                <div class="col-sm-5">
                    <div class="col-sm-4"><label for="button" class="control-label">&nbsp;</label></div>
                    <div class="col-sm-4">
                        <button type="button" class="btn btn-primary btn-block" onclick="search_data();">Search</button>
                    </div>
                    <div class="col-sm-4">
                        <button type="reset" class="btn btn-default btn-block">Clear</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div style="margin-top:20px;"></div>

    <div id="tablecontent">
        <div class="container well">
            <div class="col-sm-2" style="padding-bottom: 10px;">
                <button type="button" class="btn btn-success btn-block" onclick="add_data();">Add Area</button>
            </div>


            <table class="table table-bordered table-condensed table-striped" style="background:#f9f9f9;">
                <thead>
                    <tr>
                        <th class="tblhead" style="width:5%;text-align:center;">No</th>
						<th class="tblhead" style="width:30%;text-align:center;">Regional Name</th>
						<th class="tblhead" style="width:26%;text-align:center;">Office Name</th>
						<th class="tblhead" style="width:13%;text-align:center;">Type</th>
						<th class="tblhead" style="width:13%;text-align:center;">Status</th>
						<th class="tblhead" style="width:13%;text-align:center;">Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    if (empty($list_data)) {
                        ?>
                        <tr><td colspan="8" style="text-align:center">No Data Available</td></tr>
                        <?php
                    } else {
                        foreach ($list_data as $row) {
                            ?>
                            <tr>
                                <?php
                                $id = $row["AREA_ID"];
                                $name = $row["AREA_NAME"];
                                $desc = $row["AREA_DESC"];
                                $status = $row["AREA_STATUS"];
                                $regional_name = $row["REGIONAL_NAME"];
                                $type = $row["ISDOMESTIC"];
                                $messenger = $row["ISMESSENGER"];

                                $area_type = ($type == 'Y') ? 'Domestik' : 'Internasional';
                                $area_status = ($status == 'Y') ? 'Active' : 'Not Active';
                                ?>

                                <td style="text-align:center;"><?php echo $row["RECNUM"]; ?>.</td>
                                <td style="text-align:left;"><?php echo ucfirst($name) . ' - ' . ucfirst($desc); ?></td>
                                <td style="text-align:left;"><?php echo ucfirst($regional_name); ?></td>
                                <td style="text-align:center;"><?php echo $area_type; ?></td>
                                <td style="text-align:center;">
                                    <?php if ($status == 'Y') : ?>
                                        <a class="btn btn-sm btn-primary" href="#" onclick="activation('<?php echo $id ?>', '<?php echo $status ?>');">
                                            <?php echo $area_status; ?></a>
                                    <?php else: ?>
                                        <a class="btn btn-sm btn-danger" href="#" onclick="activation('<?php echo $id ?>', '<?php echo $status ?>');">
                                            <?php echo $area_status; ?></a>
                                    <?php endif; ?>
                                </td>
                                <td style="text-align:center;">
                                    <a class="btn btn-sm btn-warning" href="#" onclick="edit_data('<?php echo $id ?>');">
                                        Edit</a>
                                </td>
                            </tr>
                            <?php
                        }
                    }
                    ?>
                </tbody>
            </table>
            <div id="mypaging">
                <?php
                echo $paging;
                echo $jump_page;
                echo $ipp;
                ?>
            </div>
        </div>
    </div>

</div>
<div style="margin-top:20px;"></div>

<?php $this->load->view('footer'); ?>
